using HCore.Unity.Core;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Test
{
    public class PointViz : MonoBehaviour
    {
        private Vector3 mOffset;

        private void OnMouseDown()
        {
            if (EventSystem.current.IsPointerOverGameObject()) return;

            mOffset = transform.position - GameUtils.MainCamera.ScreenToWorldPoint(
                new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f)
            );
        }

        private void OnMouseDrag()
        {
            if (EventSystem.current.IsPointerOverGameObject()) return;
            var curScreenPoint = new Vector3(
                Input.mousePosition.x,
                Input.mousePosition.y, 0.0f);
            var curPosition = GameUtils.MainCamera.ScreenToWorldPoint(curScreenPoint) + mOffset;
            transform.position = curPosition;
        }

        private void OnMouseUp()
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
            }
        }
    }
}